<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>2019/1/21</title>
    <!--好的代码像粥一样,是得用时间和精力熬的。-->
  <script>
    function LocalStorage() {
      this.storage = window.localStorage;
    }
    LocalStorage.prototype = {
      get:function(key) {
        var currenTime = new Date().getTime();
        if (this.storage.getItem(key) === null){
          console.log(`当前的key:${key}无数据`);
        } else {
          var originData = this.storage.getItem(key);
          var modifyData = JSON.parse(originData);
          if (currenTime - modifyData){

          }
        }
      },
      set:function(key, value, maxAge) {
        if ( this.storage.getItem(key) === undefined){
          var val = {
            value: value,
            maxAge: maxAge || 100*24*365*3600,
            createTime: new Date().getTime()
          };
          this.storage.setItem(key,JSON.stringify(val));
        } else {
          console.log(`当前存储的key：${key}重名`)
        }
      },
      remove:function(key) {
        this.storage.removeItem(key);
      },
      clear:function() {
        this.storage.clear();
      }
    };

    var storage = new LocalStorage();
    storage.set('a', {a:1,b:2});

  </script>
</head>
<body>

</body>
</html>
